<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');
require("../include/lib/fckeditor/fckeditor.php");

if (!$content_admin) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;
if ((isset($_POST["submit"]))) {
    $updateSQL = sprintf("UPDATE petmanual SET mal_class=%s, mal_title=%s, mal_info=%s WHERE Id=%s",
                       GetSQLValueString($_POST['mal_class'], "text"),
                       GetSQLValueString($_POST['mal_title'], "text"),
                       GetSQLValueString(stripslashes($_POST['FCKeditor1']), "text"),
                      
                       GetSQLValueString($_POST['Id'], "int"));
    $db->query($updateSQL);
    header("location:".$_SERVER['PHP_SELF']."?result=suc&Id=".$_POST['Id']);
}

$id = "-1";
if (isset($_GET['Id'])) {
    $id = $_GET['Id'];
}

$sql = sprintf("SELECT * FROM petmanual WHERE Id = %s", GetSQLValueString($id, "int"));
$res = $db->query($sql);
$row = $db->fetch($res);

include('AdminPanel.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">
  <table align="center" width="60%">
    <?php
    if($_GET['result'] && 'suc' == $_GET['result']) {
    ?>
    <tr valign="baseline">
      <td colspan="2" nowrap="nowrap" align="center"><font color="green">更新成功...</font></td>
    </tr>
    <?php
    }
    ?>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">
      </select>
      标题:</td>
      <td><input type="text" name="mal_title" value="<?php echo $row['mal_title']?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">内容:</td>
      <td>
      <?php
	  $oFCKeditor = new FCKeditor('FCKeditor1') ;
	  $oFCKeditor->BasePath = FCKEDITOR_BASE_PATH;
	  $oFCKeditor->Height = 400;
	  $oFCKeditor->Value = $row['mal_info'];
	  $oFCKeditor->Create();
	  ?>
	  </td>
      </td>
    </tr>
    <?php
    if(1 === (int)$row['mal_class']) {
    	$select1 = 'selected';
    	$select2 = '';
    	$select3 = '';
    }
    else if(2 === (int)$row['mal_class']) {
    	$select1 = '';
    	$select2 = 'selected';
    	$select3 = '';
    }
    else {
    	$select1 = '';
    	$select2 = '';
    	$select3 = 'selected';
    }
    ?>
    <tr>
      <td scope="row" valign="top">分类:</td>
      <td><select name="mal_class" id="mal_class">
        <option value="1" <?php echo $select1?>>宠主须知</option>
        <option value="2" <?php echo $select2?>>宠物与小孩</option>
        <option value="3" <?php echo $select3?>>养护误区</option>
      </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td>
      	<input type="submit" id="submit" name="submit" value="Update record" />&nbsp;&nbsp;
        <input type="button" id="button" onclick="window.location.href='PetManual.php'" value="Back">
      </td>
    </tr>
    <input type="hidden" name="Id" value="<?php echo $row['Id']?>">
</form>
<p>&nbsp;</p>
</body>
</html>